package com.itheima.controller;


import com.itheima.entity.Student;
import com.itheima.service.StudentService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.xml.crypto.Data;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Controller
public class pageController {

    @Resource
    private StudentService studentService;

    @GetMapping(value = "/th")
    public String th(
            // 获取请求路径中的参数
           @RequestParam(value = "age") Integer age,
            Model model
    ){
        System.out.println("thymeleaf的使用");
        String msg="Hello world";
        model.addAttribute("age",age);
        model.addAttribute("msg",msg);

        List<Student> studentList = studentService.findAll();
        model.addAttribute("studentList",studentList);
        Date date = new Date();
        model.addAttribute("nowData",date);
        // 获取当前日期和时间
        LocalDateTime now = LocalDateTime.now();
        // 需要添加新的依赖
        model.addAttribute("now",now);

        return "index";

    }

}
